package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import model.DataBase;


public class NoiseDao {

	String url=null;
	String driver = null;
	
	Statement st=null;
	Connection con=null;
	ResultSet rs=null;
	public List<String> getLocations(DataBase db,String tbName,String field) {
		 url = db.getUrl();
		 driver = db.getDriver();
		List<String> locations = new ArrayList<String>();
		String sql="select distinct "+field+" from "+tbName;
		try{
			Class.forName(driver);
			con=  DriverManager.getConnection(url,db.getUserName(),db.getPassword());
			st = con.createStatement();
			rs = st.executeQuery(sql);
			while (rs.next()) {
				String location = rs.getString(field);
			
				locations.add(location);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return locations;
	}
}
